package com.xunfang.controller;

import com.xunfang.bean.Result;
import com.xunfang.bean.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yellow Docter
 * @date 2023 -10-11
 * @desc
 *  统一结果的封装
 */
@RestController
public class Demo02Controller {

    @RequestMapping("/user/req01")
    public Result handler01(){
        Result result = new Result();
        result.setCode(10001);
        result.setMsg("请求成功...");
        return result;
    }

    @RequestMapping("/user/req02")
    public Result handler02(){
        User user = new User(); //alt + 回车
        user.setUsername("王语嫣");
        user.setAge(40);

        Result result = new Result();
        result.setCode(10001);
        result.setMsg("请求成功...");
        result.setData(user);
        return result;
    }

    @RequestMapping("/user/req03")
    public Result handler03(){

        User user = new User(); //alt + 回车
        user.setUsername("王语嫣");
        user.setAge(40);

        User user2 = new User(); //alt + 回车
        user2.setUsername("阿朱");
        user2.setAge(40);

        User user3 = new User(); //alt + 回车
        user3.setUsername("阿紫");
        user3.setAge(30);

        List<User> users = Arrays.asList(user, user2, user3);

        Result result = new Result();
        result.setCode(10001);
        result.setMsg("请求成功...");
        result.setData(users);
        return result;
    }
}
